package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.provider.mapper.SpareLinkAddrMapper;
import com.weixing.mall.provider.model.domain.SpareLinkAddr;
import com.weixing.mall.provider.model.dto.cms.SpareLinkAddrChgEnableDto;
import com.weixing.mall.provider.model.dto.cms.SpareLinkAddrDto;
import com.weixing.mall.provider.model.vo.cms.SpareLinkAddrVo;
import com.weixing.mall.provider.service.ISpareLinkAddrService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @Author: kfc
 * @Description: <br/>
 * Date:Create in 2019/9/9 12:02
 * @Modified By:
 */
/**
 * <p>
 * 备用域名 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-18
 */
@Service
public class SpareLinkAddrServiceImpl extends ServiceImpl<SpareLinkAddrMapper, SpareLinkAddr> implements ISpareLinkAddrService {
    @Override
    public IPage<SpareLinkAddrVo> selectList(Page page) {
        return baseMapper.selectListOfPage(page);
    }

    @Override
    public void changeEnable(SpareLinkAddrChgEnableDto dto) {
        SpareLinkAddr spareLinkAddr = new SpareLinkAddr();
        spareLinkAddr.setId(dto.getId());
        spareLinkAddr.setIsEnable(dto.getIsEnable().getValue());
        updateById(spareLinkAddr);
    }

    @Override
    public void save(SpareLinkAddrDto dto) {
        SpareLinkAddr spareLinkAddr = new SpareLinkAddr();
        BeanUtils.copyProperties(dto,spareLinkAddr);
        spareLinkAddr.setIsEnable(dto.getIsEnable().getValue());
        if (null == dto.getId()){
            save(spareLinkAddr);
        }else {
            updateById(spareLinkAddr);
        }
    }
}
